const path  = require('path')
const sql = require('../module/index')
const md5 = require('md5')
const session =require('express-session')
const login ={
    
}
login.views=(req,res)=>{
    res.sendFile(path.resolve(__dirname,'../views/login.html'))
}

login.login=(req,res)=>{
    let {user,cipher} = req.body
    let str = `SELECT * FROM userinfo WHERE username='${user}' and password='${md5(cipher)}'`
    sql.query(str).then((result)=>{
        if(result[0].length==1){
            req.session.userinfo=result[0]// 赋予用户身份
            res.json({
                code:20000,
                message:"登录成功"
            })
        }else{
            res.json({
                code:40000,
                message:"账号密码错误"
            })
        }
    })
}

module.exports = login